{ config, lib, pkgs, ... }:

{
  nix = {
    package = pkgs.nixVersions.unstable;
    gc = {
      automatic = true;
      dates = "daily";
      options = "--delete-older-than 3d";
      #randomizedDelaySec = "45min";
    };
    settings = {
      sandbox = true;
      # 硬链接优化 /nix/store 节省空间
      auto-optimise-store = true;
      trusted-users = [ "root" "@wheel" ];
      experimental-features =
        [ "nix-command" "flakes" "ca-derivations" "repl-flake" ];
      builders-use-substitutes = true;
      keep-derivations = true;
      substituters = lib.mkForce [
        "https://mirror.sjtu.edu.cn/nix-channels/store"
        "https://mirrors.bfsu.edu.cn/nix-channels/store"
        "https://mirrors.tuna.tsinghua.edu.cn/nix-channels/store"
        "https://mirrors.ustc.edu.cn/nix-channels/store"
        #"https://cache.nixos.org/"
        #"https://cache.garnix.io"
      ];
      extra-substituters = [ "https://nix-community.cachix.org" ];
      # trusted-public-keys = [
      #     "$y$j9T$qiUug1KnxaW4edMijPRJx0$17.ZndPisCTKuWdtD9gGrrwsfv2uwQUmR4OMDf2yog4"
      # ];
    };
    optimise.automatic = true;
    extraOptions = ''
      keep-outputs = true
      keep-derivations = false
      fallback = true
      experimental-features = nix-command flakes
      flake-registry = /etc/nix/registry.json
    '';
  };
}
